/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mwt.xml.xdbforms.xformlayer.transactions.impl;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Definisce una classe per la creazione di oggetti
 *
 * @author Gianfranco Murador, Cristian Castiglia, Matteo Ferri
 */
public class Submission {

    private URL action = null;
    private String method = "";
    private String username = "";
    private String password = "";
    private String database = "";
    private String title = "";
    private URL schemaURL = null;
    private URL dataSrcURL = null;
    private URL valuesSrcURL = null;
    private String submissionMsg = "";
    private URL styleURL = null;
    private String model_id = "";
    private String operation = "";

    public String getModel_id() {
        return model_id;
    }

    public void setModel_id(String model_id) {
        this.model_id = model_id;
    }

    public String getOperation() {
        return operation;
    }

    public void setOperation(String operation) {

        if (operation.equalsIgnoreCase("insert")) {
            this.operation = "insert";
        } else {

            if (operation.equalsIgnoreCase("update")) {
                this.operation = "update";
            } else {

                throw new IllegalArgumentException("Please set parameter with \"insert\" or \"update\"");

            }
        }
    }

    public Submission() {
    }

    public Submission(String database, URL action, String method, URL schemaURL, URL dataSrcURL, URL valueSrcURL, String subMsg) {

        this.action = action;
        this.method = method;
        this.schemaURL = schemaURL;
        this.dataSrcURL = dataSrcURL;
        this.submissionMsg = subMsg;
        this.database = database;
        this.valuesSrcURL = valueSrcURL;


    }

    public URL getDataSrcURL() {
        return dataSrcURL;
    }

    public void setDataSrcURL(URL dataSrcURL) {
        this.dataSrcURL = dataSrcURL;
    }

    public URL getSchemaURL() {
        return schemaURL;
    }

    public void setSchemaURL(URL schemaURL) {
        this.schemaURL = schemaURL;
    }

    public URL getStyleURL() {
        return styleURL;
    }

    public void setStyleURL(URL styleURL) {
        this.styleURL = styleURL;
    }

    public URL getValuesSrcURL() {
        return valuesSrcURL;
    }

    public void setValuesSrcURL(URL valuesSrcURL) {
        this.valuesSrcURL = valuesSrcURL;
    }

    public String getSubmissionMsg() {
        return submissionMsg;
    }

    public void setSubmissionMsg(String submissionMsg) {
        this.submissionMsg = submissionMsg;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getMethod() {
        return method;
    }

    public void setMethod(String method) {

        if (method.equalsIgnoreCase("post")) {
            this.method = method;
        } else {

            if (method.equalsIgnoreCase("get")) {

                this.method = method;
            } else {

                if (method.equalsIgnoreCase("multipart-post")) {

                    this.method = method;

                } else {

                    throw new IllegalArgumentException("Please, insert or \"multipart-post\" \"post\" or \"get\" string");
                }

            }


        }

//        this.method = method;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public URL getAction() {
        return action;
    }

    public void setAction(URL action) {
        this.action = action;
    }

    public Map toHashMap() {

        Map<String, String> map = new HashMap<String, String>();
        map.put("submission_url", action.toString());
        map.put("submission_method", method);
        map.put("title", title);
        map.put("submission_msg", submissionMsg);
        map.put("data-src", dataSrcURL.toString());
        map.put("admis-val-src", valuesSrcURL.toString());
        map.put("schema_url", schemaURL.toString());
        map.put("model_id", model_id);
        map.put("operation", operation);


        if (styleURL != null) {
            map.put("style", styleURL.toString());
        }

        return map;
    }
}
